<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
   // $fields=array('id','name');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_sns_level',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'等级管理'),
			array('op'=>'edit','title'=>'添加等级'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'levelname','title'=>'等级名称','type'=>'string'),
			array('name'=>'credit','title'=>'升级条件（所需积分数量）','type'=>'string'),
			
			
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_sns_level',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'分类设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'等级管理'),
			array('op'=>'edit','title'=>'添加等级'),
		),
		'edit'=>array(
			array('name'=>'levelname','title'=>'等级名称','type'=>'string'),
			array('name'=>'credit','title'=>'升级条件','type'=>'string'),
			array('name'=>'color','title'=>'标签颜色','type'=>'color'),
			array('name'=>'bg','title'=>'背景颜色','type'=>'color'),
			)
			);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['levelname']){
		exi('请填写等级名称');
	}
	
	$data=array_fields(array('levelname','credit','color','bg','post'),$postdata);
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_sns_level',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_sns_level',$data);
				exi('添加成功！','','list');
			}
			}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_sns_level',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_sns_level',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>